Skip to content

feat(swagger): opt-in publicInProd to serve /api/spec.json in deployed envs#3879

Merged
PierreBrisorgueil merged 1 commit into
masterfrom
feat/swagger-public-spec-optin
Jun 15, 2026
Merged

feat(swagger): opt-in publicInProd to serve /api/spec.json in deployed envs#3879
PierreBrisorgueil merged 1 commit into
masterfrom
feat/swagger-public-spec-optin

Conversation

@PierreBrisorgueil

Copy link
Copy Markdown
Contributor

Adds a generic, secure-by-default opt-in so a consumer with intentionally-public API docs can serve the unauthenticated /api/spec.json in production-grade (deployed) envs.

The spec gate was config.swagger.enable && !isProd() → spec served only in dev-grade (local), skipped in any deployed env. That breaks the in-app OpenAPI reference for a public-docs consumer. New gate:

if (config.swagger.enable && (!configHelper.isProd() || config.swagger.publicInProd === true)) {
  • config.swagger.publicInProd defaults false (secure-by-default preserved — opt-in narrows nothing for projects that don't want public docs).
  • New env-gate test case: isProd() true + publicInProd:true → spec served (merged guides intact); Redoc stays decommissioned.

Lint + express/docs-env-gate + public-docs tests green.

…d envs

Secure-by-default stays: the unauthenticated /api/spec.json is skipped in
production-grade envs. Consumers with intentionally-public API docs can now
opt in via config.swagger.publicInProd === true (defaults false). enable must
still be truthy — the opt-in narrows the gate, never widens it. Redoc stays
decommissioned; /api/docs is not re-introduced.
Copilot AI review requested due to automatic review settings June 15, 2026 20:00
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@PierreBrisorgueil, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 59 minutes and 55 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 73e7ec47-6f64-4931-93be-ce1a6529ed21

📥 Commits

Reviewing files that changed from the base of the PR and between 580f6a3 and 07d194f.

📒 Files selected for processing (3)
  • config/defaults/development.config.js
  • lib/services/express.js
  • lib/services/tests/express.docsEnvGate.unit.tests.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/swagger-public-spec-optin

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a secure-by-default opt-in (config.swagger.publicInProd === true) to allow serving the unauthenticated OpenAPI JSON spec (/api/spec.json) in production-grade (deployed) environments for consumers that intentionally publish public API docs.

Changes:

  • Updates initApiSpec env gate to allow /api/spec.json in prod only when explicitly opted in via config.swagger.publicInProd === true.
  • Adds a unit test covering the production-grade + opt-in path, including asserting the merged spec is still served.
  • Introduces swagger.publicInProd: false in the default development config to document/establish the new knob as off by default.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
lib/services/express.js Extends the docs env gate to support an explicit prod opt-in for serving /api/spec.json.
lib/services/tests/express.docsEnvGate.unit.tests.js Adds coverage ensuring the spec mounts in prod only when publicInProd === true and Redoc remains disabled.
config/defaults/development.config.js Defines swagger.publicInProd with a default of false (secure-by-default).

@PierreBrisorgueil PierreBrisorgueil merged commit 8e89a21 into master Jun 15, 2026
7 checks passed
@PierreBrisorgueil PierreBrisorgueil deleted the feat/swagger-public-spec-optin branch June 15, 2026 20:04
@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.67%. Comparing base (580f6a3) to head (07d194f).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3879   +/-   ##
=======================================
  Coverage   92.67%   92.67%           
=======================================
  Files         169      169           
  Lines        5529     5529           
  Branches     1775     1776    +1     
=======================================
  Hits         5124     5124           
  Misses        325      325           
  Partials       80       80           
Flag Coverage Δ
integration 61.13% <100.00%> (ø)
unit 74.22% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 580f6a3...07d194f. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants